import request from '@/utils/request'

/**
 * 搜索接口，已自动筛选失效管理员
 * @param filter 搜索筛选器
 * @param index 页码
 * @param size 页面大小
 * @returns {AxiosPromise}
 */
export function search(filter, index, size) {
  filter.valid = 0
  return request({
    url: '/dish/search',
    method: 'post',
    data: {
      filter,
      index,
      size
    }
  })
}
/**
 * 更新接口
 * @param filter 更新筛选器
 * @param update 更新结果
 * @returns {AxiosPromise}
 */
export function update(filter, update) {
  filter.valid = 0
  update.valid = 0
  return request({
    url: '/dish/update',
    method: 'post',
    data: {
      filter,
      update
    }
  })
}
/**
 * 标记生效接口
 * @param filter 标记筛选器
 * @returns {AxiosPromise}
 */
export function invalid(filter) {
  return request({
    url: '/dish/invalid',
    method: 'post',
    data: {
      filter
    }
  })
}
/**
 * 添加接口
 * @param filter 新管理员
 * @returns {AxiosPromise}
 */
export function add(dish, dishToFoods) {
  return request({
    url: '/dish/add',
    method: 'post',
    data: {
      dish,
      dishToFoods
    }
  })
}

export function updateRelationship(dish,dishToFoods) {
  return request({
    url: '/dish/updateRelationship',
    method: 'post',
    data: {
      dish,
      dishToFoods
    }
  })
}

export function searchFoodByDishId(filter) {
  return request({
    url: '/dish/searchFoodByDishId',
    method: 'post',
    data: {
      filter
    }
  })
}

export function searchDefaultFood(filter, index, size) {
  filter.createUser = 0
  return request({
    url: '/food/searchDefault',
    method: 'post',
    data: {
      filter,
      index,
      size
    }
  })
}

